package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.sc.nft.entity.vo.AdminPledgeCollectionRecordsVO;
import com.sc.nft.entity.vo.UserVigorousCollectionVO;
import com.sc.nft.enums.PledgeStatusEnum;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.UserPledgeCollectionRecords;
import com.sc.nft.mapper.UserPledgeCollectionRecordsMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 质押任务-用户质押记录-关联藏品和奖励表(sc_user_pledge_collection_records)数据DAO
 *
 * @author kancy
 * @since 2023-06-13 14:55:02
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class UserPledgeCollectionRecordsDao extends ServiceImpl<UserPledgeCollectionRecordsMapper, UserPledgeCollectionRecords> {

    public AdminPledgeCollectionRecordsVO getCollectioInfoByUserPledgeRecordsId(Long userPledgeRecordsId) {
        return baseMapper.getCollectioInfoByUserPledgeRecordsId(userPledgeRecordsId);
    }

    public List<UserVigorousCollectionVO> getPledgeCollectionIdByUserPledgeRecordsId(Long userPledgeRecordsId) {
        return baseMapper.getPledgeCollectionIdByUserPledgeRecordsId(userPledgeRecordsId);
    }

    public List<UserPledgeCollectionRecords> getListByUserIdAndUserPledgeRecordsIdAndPledgeStatus(Long userId, Long userPledgeRecordsId, PledgeStatusEnum pledgeStatus) {
        LambdaQueryWrapper<UserPledgeCollectionRecords> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserPledgeCollectionRecords::getUserId, userId);
        wrapper.eq(UserPledgeCollectionRecords::getUserPledgeRecordsId, userPledgeRecordsId);
        wrapper.eq(UserPledgeCollectionRecords::getPledgeStatus, pledgeStatus);
        return list(wrapper);
    }

    public Boolean updatePledgeStatusByUserPledgeRecordsId(Long userPledgeRecordsId, PledgeStatusEnum pledgeStatusEnum) {
        UpdateWrapper<UserPledgeCollectionRecords> wrapper = new UpdateWrapper<>();
        wrapper.eq("user_pledge_records_id", userPledgeRecordsId);
        wrapper.set("pledge_status", pledgeStatusEnum.getCode());
        return update(new UserPledgeCollectionRecords(), wrapper);
    }
}